package feesmodule.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@Table(name="CONDITION_ELEMENT")
public class ConditionElement implements Serializable
{
    public static final int CONDITION_IS = 1;
    public static final int CONDITION_IS_NOT = 2;

    @Id
    @Column(name="CONDITION_ELEMENT_ID")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;
    
    @Column(name="OPERATOR" )
    private int operator = CONDITION_IS;

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="TYPE_DEF_ID")
    private TypeDefinition typeDefinition;
    
    @ManyToMany
    @JoinTable(
    name = "VALUES_MAPPING", joinColumns={@JoinColumn(name="CONDITION_ID")},
            inverseJoinColumns={@JoinColumn(name="DOMAIN_DEF_ID")}
            )
    private Set<DomainDefinition> values = new HashSet<DomainDefinition>();

    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="CONDITION_SET_ID")
    private ConditionSet condition;

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the operator
     */
    public int getOperator() {
        return operator;
    }

    /**
     * @param operator the operator to set
     */
    public void setOperator(int operator) {
        this.operator = operator;
    }

    /**
     * @return the values
     */
    public Set<DomainDefinition> getValues() {
        return values;
    }

    /**
     * @param values the values to set
     */
    public void setValues(Set<DomainDefinition> values) {
        this.setValues(values);
    }

    /**
     * @return the typeDefinition
     */
    public TypeDefinition getTypeDefinition() {
        return typeDefinition;
    }

    /**
     * @param typeDefinition the typeDefinition to set
     */
    public void setTypeDefinition(TypeDefinition typeDefinition) {
        this.typeDefinition = typeDefinition;
    }

    /**
     * @return the condition
     */
    public ConditionSet getCondition() {
        return condition;
    }

    /**
     * @param condition the condition to set
     */
    public void setCondition(ConditionSet condition) {
        this.condition = condition;
    }



}
